<template>
  <div class="queryBody">
    <el-card>
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-ruleForm"
        size="mini"
        ref="searchForm"
        label-width="100px"
      >
        <el-row>
          <el-col :span="5">
            <el-form-item label="项目名称">
              <el-input
                v-model="formInline.projectName"
                placeholder=""
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="濞茶濮╅崠鍝勭厵">
              <el-select
                v-model="formInline.region"
                placeholder="濞茶濮╅崠鍝勭厵"
              >
                <el-option label="閸栧搫鐓欐稉鈧�" value="shanghai"></el-option>
                <el-option label="閸栧搫鐓欓敓锟�?" value="beijing"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="creationTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="创建用户">
              <el-input
                v-model="formInline.createUser"
                placeholder="创建用户"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="批次号">
              <el-input
                v-model="formInline.checkUploadNum"
                placeholder="批次号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="用户">
              <el-input v-model="formInline.user" placeholder="用户"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="2">
            <el-button
              type="primary"
              @click="search"
              icon="el-icon-search"
              size="mini"
              >查询</el-button
            >
          </el-col>
          <el-col :span="2">
            <el-button
              type="warning"
              @click="reSetSubmit"
              icon="el-icon-refresh"
              size="mini"
              >重置</el-button
            >
          </el-col>
          <el-col :span="2">
            <el-button
              type="primary"
              @click="exportFile"
              icon="el-icon-download"
              size="mini"
              >导出</el-button
            >
          </el-col>
          <el-col :span="2">
            <el-button
              type="success"
              @click="addUser"
              icon="el-icon-plus"
              size="mini"
              >添加</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!--table -->
    <div class="common-table">
      <el-table
        :data="tableData"
        border
        height="90%"
        size="mini"
        header-align="center"
      >
        <el-table-column fixed prop="creationTime" label="创建时间" width="180">
        </el-table-column>
        <el-table-column prop="projectName" label="项目名称" width="180">
        </el-table-column>
        <el-table-column prop="createUser" label="创建用户" width="120">
        </el-table-column>
        <el-table-column prop="checkUploadNum" label="批次号" width="180">
        </el-table-column>
        <el-table-column prop="address" label="地址" width="200">
        </el-table-column>
        <el-table-column prop="zip" label="文件" width="120"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="410" align="center">
          <template slot-scope="scope">
            <el-button @click="edit(scope.row)" type="text" size="small"
              >修改</el-button
            >
            <el-button @click="remove(scope.row)" type="text" size="small"
              >删除</el-button
            >
            <el-button @click="viewupload(scope.row)" type="text" size="small"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pager">
        <el-pagination background layout="prev, pager, next" :total="1000">
        </el-pagination>
      </div>
    </div>
    <el-dialog title="添加" :visible.sync="addVisible">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="检测项目">
          <el-input
            v-model="formInline.projectName"
            placeholder="检测项目"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建用户">
          <el-input
            v-model="formInline.createUser"
            placeholder="创建用户"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addSubmit">添加</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- -->
    <el-dialog title="上传" :visible.sync="uploadVisible">
      <el-upload
        class="upload-demo"
        drag
        ref="upload"
        action="https://localhost:7106/api/UploadFile/AddUPloadDetail"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :file-list="fileList"
        :before-remove="beforeRemove"
        :data="uploadData"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">上传文件</div>
      </el-upload>
    </el-dialog>
  </div>
</template>
CheckUploadNum
<script>
import {
  GetUsers,
  GetDetailInfo,
  DelInfoByDetailNum,
  AddUPload,
  DownFile,
} from "network/Home.js";
export default {
  name: "VueSysmangerUser",

  data() {
    return {
      formInline: {
        checkUploadNum: "",
        projectName: "",
        createUser: "",
        startDate: "",
        endDate: "",
        pageIndex: 0,
        pageSize: 10,
      },
      creationTime: "",
      tableData: [
        {
          checkUploadNum: "20240425Xie5884",
          uploadState: false,
          creationTime: "2023-04-11 14:06:41",
          projectName: "发射点发射点",
          createUser: "房贷首付",
        },
      ],
      addVisible: false,
      uploadVisible: false,
      currentUploadNum: "",
      uploadData: {
        CheckUploadNum: this.currentUploadNum,
      },
      fileList: [], //娑撳﹣绱堕崚妤勩€�
    };
  },
  components: {},
  mounted() {},

  methods: {
    exportFile() {
      DownFile("132").then((res) => {
        console.log(res.headers);
        const fileName = window.decodeURI(
          res.headers["content-disposition"].split("=")[1],
          "UTF-8"
        );
        console.log(res.data);
        // 前面responseType设置的 “blob” 后台返回的response直接就是 blob对象，前端不用再去new Blob了
        if (window.navigator.msSaveOrOpenBlob) {
          navigator.msSaveBlob(res.data, fileName);
        } else {
          // let content = [];
          // content.push(res.data);
          // // new Blob 实例化文件流
          // const blobData = new Blob(content, { type: "application/pdf" });
          let link = document.createElement("a");
          link.download = fileName;
          link.href = window.URL.createObjectURL(res.data);
          link.click();
          // 释放内存
          window.URL.revokeObjectURL(link.href);
        }
      });
    },
    reSetSubmit() {
      this.$refs.searchForm.resetFields();
    },
    search() {
      try {
        this.formInline.startDate = this.creationTime[0].toString();
        this.formInline.endDate = this.creationTime[1].toString();
        console.log(this.formInline);
        GetUsers(this.formInline).then((res) => {
          if (res.stateCode === 200) {
            this.tableData = res.data;
          } else {
          }
        });
      } catch (error) {
        console.log(error);
      }
    },
    addSubmit() {
      AddUPload(this.formInline).then((res) => {
        console.log(res);
      });
    },
    addUser() {
      this.addVisible = true;
    },
    edit(row) {},
    handleRemove(file, fileList) {
      console.log(file);

      DelInfoByDetailNum(file.uploadDetailNum).then((res) => {
        if (res.stateCode === 200) {
          this.$message({
            type: "success",
            message: res.message,
          });
        } else {
          this.$message({
            type: "danger",
            message: res.message,
          });
        }
      });
    },
    handlePreview(file) {
      console.log(file);
      window.open(file.url);
    },
    viewupload(row) {
      this.fileList = [];
      //this.$refs.upload.clearFiles();
      GetDetailInfo(row.checkUploadNum).then((res) => {
        if (res.stateCode === 200) {
          for (const item of res.data) {
            let file = {
              name: item.fileName,
              url: item.uploadDetailNum,
              uploadDetailNum: item.uploadDetailNum,
            };
            this.fileList.push(file);
          }
          this.uploadVisible = true;
        }
      });
    },
    submitUpload(row) {
      this.currentUploadNum = row.CheckUploadNum;
      this.$refs.upload.submit();
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`你确定删除 ${file.name}文件`);
    },
  },
};
</script>
<style lang="less" scoped>
.queryBody {
  height: 70%;
  .common-table {
    position: relative;
    height: calc(100% - 62px);
    .pager {
      position: absolute;
      bottom: 0;
      right: 20px;
    }
  }
}
</style>